#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>

//https://www.luogu.com.cn/problem/P1706

using namespace std;
const int N = 12;
int n;
bool st[N];
vector<int> path;

void dfs()
{
	if (path.size() == n)
	{
		for (int e : path)printf("%5d", e);
		cout << endl;
	}

	for (int i = 1; i <= n; ++i)
	{
		if (st[i])continue;
		path.push_back(i);
		st[i] = true;
		dfs();
		st[i] = false;
		path.pop_back();
	}
}

int main()
{
	cin >> n;

	dfs();

	return 0;
}